#include<iostream>
#include<vector>
using namespace std;

int jump(vector<int>& nums) {
    int n = nums.size();
    int left = 0, right = 0, maxstep = 0, ret = 0;
    while (left <= right)
    {
        if (maxstep >= n - 1)
        {
            return ret;
        }
        for (int i = left; i <= right; i++)
        {
            maxstep = max(maxstep, nums[i] + i);
        }
        left = right + 1;
        right = maxstep;
        ret++;
    }
    return -1;
}

int main()
{
    vector<int>nums{ 2,3,1,1,4 };
    cout << jump(nums) << endl;
    return 0;
}